package com.echo.code.arithmetic.chapter08;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * Created by baiyap on 2018/8/15.
 */
public class Collections {

  /**
   * 浅层拷贝.
   * */
  public static <E> Set<E> fork(Set<E> set) {
    Set<E> newSet = new HashSet<>();
    if (Objects.nonNull(set)) {
      set.forEach(e -> newSet.add(e));
    }
    return newSet;
  }

  public static <E> List<E> fork(List<E> list) {
    List<E> newList = new LinkedList<>();
    if (Objects.nonNull(list)) {
      list.forEach(e -> newList.add(e));
    }
    return newList;
  }

  public static <E> Set<E> unmodifiableSet(Set<E> set) {
    return java.util.Collections.unmodifiableSet(set);
  }

  public static <E> List<E> unmodifiableList(List<E> list) {
    return java.util.Collections.unmodifiableList(list);
  }
}
